package com.bff.gaia.mix.api.xjoin.client.hbase.async;

import com.bff.gaia.api.java.typeutils.RowTypeInfo;
import com.bff.gaia.mix.api.xjoin.client.hbase.core.RowKeyBuilder;
import com.bff.gaia.mix.api.xjoin.client.hbase.core.table.HbaseSideTableInfo;
import com.bff.gaia.mix.api.xjoin.core.side.FieldInfo;
import com.bff.gaia.mix.api.xjoin.core.side.JoinInfo;
import com.bff.gaia.mix.api.xjoin.core.side.SideInfo;
import com.bff.gaia.mix.api.xjoin.core.side.SideTableInfo;
import com.bff.gaia.shaded.guava18.com.google.common.collect.Maps;

import java.util.List;
import java.util.Map;

public class HbaseAsyncSideInfo extends SideInfo {
	private static final long serialVersionUID = 257688427401088045L;

	private RowKeyBuilder rowKeyBuilder;

	private Map<String, String> colRefType;

	public HbaseAsyncSideInfo(RowTypeInfo rowTypeInfo, JoinInfo joinInfo, List<FieldInfo> outFieldInfoList, SideTableInfo sideTableInfo) {
		super(rowTypeInfo, joinInfo, outFieldInfoList, sideTableInfo);
	}

	@Override
	public void buildEqualInfo(JoinInfo joinInfo, SideTableInfo sideTableInfo) {
		HbaseSideTableInfo hbaseSideTableInfo = (HbaseSideTableInfo) sideTableInfo;
		if (!hbaseSideTableInfo.isQualifierQuery()){
			rowKeyBuilder = new RowKeyBuilder();
			if(sideTableInfo.getPrimaryKeys().size() < 1){
				throw new RuntimeException("Primary key dimension table must be filled");
			}
			rowKeyBuilder.init(sideTableInfo.getPrimaryKeys().get(0));
		}
				colRefType = Maps.newHashMap();
		for(int i=0; i<hbaseSideTableInfo.getColumnRealNames().length; i++){
			String realColName = hbaseSideTableInfo.getColumnRealNames()[i];
			String colType = hbaseSideTableInfo.getFieldTypes()[i];
			colRefType.put(realColName, colType);
		}
	}

	public RowKeyBuilder getRowKeyBuilder() {
		return rowKeyBuilder;
	}

	public void setRowKeyBuilder(RowKeyBuilder rowKeyBuilder) {
		this.rowKeyBuilder = rowKeyBuilder;
	}

	public Map<String, String> getColRefType() {
		return colRefType;
	}

	public void setColRefType(Map<String, String> colRefType) {
		this.colRefType = colRefType;
	}
}